<style>
    #user-update {
        padding: 20px 25px 25px 0;
    }
</style>
<div class="layui-fluid" id="user-update">
    <form class="layui-form" action="" lay-filter="quest-detail">

        <div class="layui-form-item febs-hide">
            <label class="layui-form-label febs-form-item-require">id:</label>
            <div class="layui-input-block">
                <input type="text" name="id" minlength="4" maxlength="10"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label febs-form-item-require">标题:</label>
            <div class="layui-input-block">
                <input type="text" name="title" minlength="4" maxlength="10"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选项1：</label>
            <div class="layui-input-block">
                <input type="text" name="awan1" minlength="4" maxlength="10"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选项2：</label>
            <div class="layui-input-block">
                <input type="text" name="awan2" minlength="4" maxlength="10"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选项3：</label>
            <div class="layui-input-block">
                <input type="text" name="awan3" minlength="4" maxlength="10"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" align="center">
            <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit
                    lay-filter="quest-update-submit" id="submit">
                <i style="display: none; margin-left: 30px"
                   class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop"></i>
               跟新编辑
            </button>
        </div>

    </form>
</div>

<script data-th-inline="javascript">
    layui.use(['febs', 'form'], function () {
        let $ = layui.$,
            febs = layui.febs,
            layer = layui.layer,
            data = [[${data}]],
            form = layui.form;

        form.render();
        initValue();


        function initValue() {
            form.val("quest-detail", {
                "id": data.questionnaireVo.id,
                "title": data.questionnaireVo.title,
                "awan1": data.listAnswerVo[0].title,
                "awan2": data.listAnswerVo[1].title,
                "awan3": data.listAnswerVo[2].title

            });
        }

        form.on('submit(quest-update-submit)', function (data) {
            if (!data.field.title) {
                febs.alert.warn('请输入标题');
                return false;
            }
            if (!data.field.awan1) {
                febs.alert.warn('请输入选项-1');
                return false;
            }
            if (!data.field.awan2) {
                febs.alert.warn('请输入选项-2');
                return false;
            }
            if (!data.field.awan3) {
                febs.alert.warn('请输入选项-3');
                return false;
            }
            let loading = $(this).find('.layui-icon');
            if (loading.is(":visible")) return;
            loading.show();

            febs.post(ctx + 'web/update/questionnaire', data.field, function (data) {
                if (data.code === 200) {
                    layer.closeAll();
                    window.location.reload();
                }
            });
            return false;
        });
    });
</script>